// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using Microsoft.Extensions.Logging;

namespace SnapObjects.Expressions
{
    internal class EvaluateMetadataManager : MetadataManager<EvaluateResult>
    {
        public EvaluateMetadataManager(IServiceProvider services, ILogger<EvaluateMetadataManager> logger)
            : base(services, logger)
        {
        }

        protected override MetadataCollection<EvaluateResult> CreateCollection()
        {
            return new EvaluateMetadataCollection();
        }

        protected override Metadata<EvaluateResult> MergeMethodMetadata(
            Metadata<EvaluateResult> metadata, Metadata<EvaluateResult> from)
        {
            if (from.Type == MetadataType.Method && from is EvaluateMethodMetadata methods)
            {
                if (metadata is EvaluateMethodMetadata source)
                {
                    this.AddMethods(source, methods);

                    return source;
                }
                else
                {
                    return new EvaluateMethodMetadata(methods);
                }
            }

            return metadata;
        }
    }
}
